import env from "@/config";
const uploadUri = env.baseUrl+ "/file/upload";

const upload = (filePath) => {
    return new Promise((resolve, reject) =>{
        uni.uploadFile({
            url: uploadUri,
            name: 'file',
            filePath: filePath,
            success: res=> {
                if (res.data.code != 200){
                    uni.showToast({
                        title: res.data.message,
                        icon: 'none'
                    });
                    reject(res.data)
                }else {
                    resolve(res.data)
                }
            },
            fail: err => {
                reject(err)
            }
        })
    })
};

export default {
    upload
}